<template>
  <div class="c-bg-sgray">
    <pay-password v-show="showPassword" :price="totalPrice" @hidePwd='hidePwd' @confirmPwd='confirmPwd' class="c-pz100"></pay-password>
    <div class="c-pb8">
      <section v-if="hasGoodsGiftNew" class="c-mb14 c-bg-white c-ph24 c-pv24" @click="popAddAddress">
        <div class="c-flex-row c-aligni-center">
          <div class="iconfont c-fs30 c-fc-sgray c-mr20">&#xe6e2;</div>
          <div v-if="currentAddress" class="c-w0 c-flex-grow1">
            <div class="c-flex-row c-aligni-center c-w80">
              <div class="c-fs28 c-fw600 c-fc-xblack c-text-ellipsis1">{{ currentAddress.name }}</div>
              <div class="c-fs28 c-fw600 c-fc-xblack c-ml28 c-ws-n">{{ currentAddress.mobile }}</div>
            </div>
            <div class="c-fs24 c-fc-xblack c-w80 c-text-ellipsis1 c-mt10">{{ currentAddress.province + currentAddress.city + currentAddress.area + currentAddress.address }}</div>
          </div>
          <div v-else class="c-w0 c-flex-grow1">
            <div class="c-fs28 c-fc-xblack c-pv24 c-lh">请选择收货地址</div>
          </div>
          <div class="iconfont c-fs24 c-fc-gray">&#xe635;</div>
        </div>
      </section>
      <!--赠送会员 isFrom 为 3 是来自升级服务上必须购买指定会员，orderId不为空表明是来自订单已指定会员选项，所以不需要会员选择-->
      <!-- isFrom 为 4 企业团购 -->
      <vip-template
        v-show="(isFrom != 3 && (ptFrom == cfrom.presentVip || ptFrom == cfrom.presentSvip || ptFrom == cfrom.flashSalesPresentVip || ptFrom == cfrom.flashSalesPresentSvip)) || isFrom == 4"
        :vipGroupPurchase='isFrom == 4 ? 2 : 1' @chooseVip="chooseVip" @groupBuyChange="groupBuyChange">
      </vip-template>
      <!--会员的购买-->
      <div class="c-ph24 c-pv30 c-bg-white c-flex-row"
        v-show="(!(ptFrom == cfrom.presentVip || ptFrom == cfrom.presentSvip || ptFrom == cfrom.flashSalesPresentVip || ptFrom == cfrom.flashSalesPresentSvip) || isFrom == 0 || isFrom == 3) && isFrom != 4">
        <div class="c-ww180 c-hh120 c-p c-br16 c-text-hidden">
          <vip-custom-img v-if="good.cover" :cover="good.cover" :imgClass="'c-ww180 c-hh120'" :fontClass="{
            boxStyle: 'c-pv30 c-pl12',
            name: 'c-fs20 c-text-ellipsis1',
            duration: 'c-fs16'}" :content="{name: good.name, duration: good.duration, durationType: good.durationType}" />
          <img v-else-if="vipType == 2" :src="require('@/assets/i/wap/course/vip.png')" alt="" class="w180 h120 img-pe-none c-br10" />
          <img v-else-if="vipType == 4" :src="require('@/assets/i/wap/course/svip.png')" alt="" class="w180 h120 img-pe-none c-br10" />
        </div>
        <div class="c-pl20 c-flex-column c-justify-sb">
          <span class="c-fs28">{{good.name}}</span>
          <span class="c-fs22 c-fc-gray" v-if="groupId">{{'拼团会员'}}</span>
          <span class="c-fs22 c-fc-gray" v-if="attendId">{{'砍价购会员'}}</span>
          <span class="c-fs22 c-fc-gray" v-if="recType == 3">{{'推荐有礼会员'}}</span>
          <div class="c-fs22 c-fc-gray" v-else-if="pId && good.sales || isShowReNew && good.duration>0">
            <span v-if="pId && good.sales">{{good.sales.tags + '专享'}}</span>
            <span v-if="isShowReNew && good.duration>0 &&!(pId && good.sales)">{{'(以' + Number(Number(good.renewRate * good.price/100).toFixed(2)) + '元续费)'}}</span>
          </div>
          <div class="c-fs18">
            <span class="c-flex-shrink0 c-fw600 c-fs24">{{'￥' | iosPriceFilter}}{{showPrice}}</span>
            <span class="c-fc-gray c-text-decoration-through c-pl20" v-if="attendId && good.linePrice">{{'￥' | iosPriceFilter}}{{good.linePrice}}</span>
            <span class="c-fc-gray c-text-decoration-through c-pl20" v-else-if="good.isNewUser && good.newUserPrice || pId || isShowReNew">{{'￥' | iosPriceFilter}}{{good.price}}</span>
            <span class="c-fc-gray c-text-decoration-through c-pl20" v-else-if="good.marketPrice && Number(good.marketPrice)">{{'￥' | iosPriceFilter}}{{good.marketPrice}}</span>
          </div>
        </div>
      </div>
      <section class="c-mt14 c-bg-white c-ph24 c-pv15" v-if="isShowPriceInfo">
        <div v-if="isShowChainInfo" class="c-pv15">
          <div class="c-flex-row c-aligni-center c-fs24">
            <span class="c-flex-grow1 c-w0">{{chainInfo && chainInfo.isReorder ? '复购优惠' : '购买优惠'}}</span>
            <span class="c-fs24 c-fc-xmlred c-fw600">-{{ "￥" | iosPriceFilter }}{{ (Number(showPrice) - Number(chainInfo.chainDiscountPrice)).toFixed(2) }}</span>
          </div>
        </div>
        <div @click="showCoupon" v-if="isShowSelectCoupon" class="c-flex-row c-aligni-center c-pv15">
          <div class="c-flex-grow1 c-w0 c-fs24 c-lh">优惠券</div>
          <div class="c-flex-row c-aligni-center">
            <div class="c-fs24 c-fc-xmlred c-fw600" v-if="choosedCouponPrice>0">-{{ "￥" | iosPriceFilter }}{{choosedCouponPrice}}</div>
            <div class="c-fs24 c-fc-gray" v-if="choosedCouponPrice <= 0">{{couponNumber > 0 ? `${couponNumber}张可用`:'无可用优惠券'}}</div>
            <div class="iconfont c-fs16 c-fc-gray c-pl10">&#xe60e;</div>
          </div>
        </div>
        <div class="c-flex-row c-justify-sb c-aligni-center c-pv15" v-if="isShowUsePoint">
          <span class="c-fs24">{{'用'+ Math.ceil(Number(memberInfo.rmb2Points * getDeductible())) + customPointName +'抵扣'}}{{'￥' | iosPriceFilter}}{{getDeductible() + '元'}}</span>
          <x-switch :themeColor="$getThemeColor()" title="" :value-map="[0, 1]" v-model="isUserPoints" @on-change="changeSwitch()"></x-switch>
        </div>
        <div v-if="isInvoice == 1 && payType != 2" @click="clickShowInvoice" class="c-pv15 c-flex-row c-aligni-center c-fs24">
          <span class="c-flex-grow1 c-w0">是否需要开发票</span>
          <span class="c-fs24 c-fc-gray">{{ !invoiceInfo ? "不开发票" : "开发票" }}</span>
          <div class="iconfont c-fs16 c-fc-gray c-pl10">&#xe60e;</div>
        </div>
      </section>

      <pay-and-vip v-if="showPayAndVip" ref="payAndVip" :ckFrom="Number(ckFrom)" @clickPayType="clickPayType" :balance="memberInfo.balance" :isOnline="1"
        :totalPrice="totalPrice.toString()" :enableGiftCard="enableGiftCard" :coinBalance="memberInfo.coinAmount" :totalCoin="totalCoin" :enablePayKnowledge="payConf && payConf.enablePayMember" :enableWxpay="!!(payConf.enableWxpay == 1)">
      </pay-and-vip>

      <div class="c-pb80">
        <div v-if="isFromPresent" @click="clickBuy" class="c-hh72 c-fs26 c-fw700 c-br40 c-flex-row c-flex-center c-mh24 c-mt32" :class="payType == -1 ? 'c-fc-white c-bg-ccc' : 'buy-btn'">
          <span v-if="payType != 2">确认支付{{'￥' | iosPriceFilter}}{{totalPrice}}</span>
          <span v-else>{{totalCoin > memberInfo.coinAmount ? `${giftCardName}不足，${$isWxApp() ? '请联系商家' : '立即充值'}` :`确认${$isWxApp() ? '消耗' : '支付'}${totalCoin}${giftCardName}`}}</span>
        </div>
        <div v-else-if="isHasVipPermission" class="c-hh72 c-fs26 c-fw700 c-br40 c-flex-row c-flex-center buy-btn c-mh24 c-mt32">{{'您已享受权益'}}</div>
        <div v-else @click="clickBuy" class="c-hh72 c-fs26 c-fw700 c-br40 c-flex-row c-flex-center c-mh24 c-mt32" :class="payType == -1 ? 'c-fc-white c-bg-ccc' : 'buy-btn'">
          <span v-if="payType != 2">确认支付{{'￥' | iosPriceFilter}}{{totalPrice}}</span>
          <span v-else>{{totalCoin > memberInfo.coinAmount ? `${giftCardName}不足，${$isWxApp() ? '请联系商家' : '立即充值'}` :`确认${$isWxApp() ? '消耗' : '支付'}${totalCoin}${giftCardName}`}}</span>
        </div>
        <section v-if="protocolInfo" class="c-ph24 c-lh42 c-mt40 c-fs20 theme-fc" @click="isCheckAgreement = !isCheckAgreement">
          <i v-show="!isCheckAgreement" class="iconfont c-fs26 c-lh42 c-fc-gray c-pr16">&#xe6f7;</i>
          <i v-show="isCheckAgreement" class="iconfont c-fs26 c-lh42 theme-fc c-pr16">&#xe796;</i>
          <span class="c-fc-gray">已阅读并同意</span>
          <span @click.stop="clickProtocol(item)" v-for="(item, index) in protocolInfo" :key="index">《{{item.name}}》</span>
        </section>
      </div>
    </div>
    <div v-if="isShowQr">
      <div class="payMasker" @click="hideQrcode()"></div>
      <div class="maskerContent c-p c-flex-column c-aligni-center">
        <div class="c-fc-xblack c-fs28 c-mt100"><i class="icon iconfont c-fs32 c-fc-green c-mr12">&#xe82e;</i>恭喜您，支付成功!</div>
        <div class="c-fs20 c-fc-gray c-mt64">——为了您更好地学习，请长按图片关注公众号——</div>
        <div class="c-flex-column c-aligni-center c-bg-white c-ww500 c-hh500 c-mt32">
          <img :src="$addXossFilter(gzhQrCode, require('../../../assets/no_chat_img.png'))" class="c-ww360 c-mt32" />
          <span class="c-fs24 theme-fc c-mt28">长按二维码，识别并关注</span>
        </div>

        <div class="c-pa c-fs28 c-fc-sgray c-p-t0 c-p-r0" @click="hideQrcode()">X</div>
      </div>
    </div>
    <!-- 显示入群引导支付成功页 -->
    <div class="payPolitelyMasker c-ph24" v-if="orderInfo && isShowPolitely">
      <div class="c-flex-row c-aligni-center c-justify-center c-mt60 c-mb50">
        <i class="iconfont c-fs40 c-fc-deepGreen c-mr10">&#xe6eb;</i>
        <span class="c-fs28 c-fc-xblack c-fw-b c-fc-deepGreen">支付成功</span>
      </div>
      <!-- 支付内容 -->
      <div class="c-flex-row c-aligni-center c-justify-sa c-mb60">
        <div class="c-flex-column c-flex-center">
          <p class="c-fs24 c-fc-gray c-mb10">支付金额</p>
          <p class="c-fs24 c-fc-xblack c-fw-b">{{'￥' | iosPriceFilter}}{{orderInfo.payMoney}}</p>
        </div>
        <div class="c-flex-column c-flex-center" v-if="orderInfo.addPoint != 0">
          <p class="c-fs24 c-fc-gray c-mb10">{{ customPointName }}奖励</p>
          <p class="c-fs24 c-fc-xblack c-fw-b">获得{{orderInfo.addPoint}}{{ customPointName }}</p>
        </div>
      </div>
      <!-- 返回个人中心 -->
      <div class="c-flex-row c-aligni-center c-justify-center c-mb30">
        <div class="c-flex-row c-aligni-center c-justify-center c-ww200 c-hh56 c-br32 view-btn c-bg-white c-fs24 c-fc-deepGreen" @click="handleClickDetail()">查看详情</div>
      </div>
      <!-- 二维码 -->
      <div class="c-flex-column c-justify-center c-aligni-center c-mt40" v-if="orderInfo.guideData.isOpenGuide == 1 && orderInfo.guideData.guideType.includes(2)">
        <p class="c-fs24 c-fc-xblack c-fw400" v-if="orderInfo.guideData.guideDesc != ''">{{orderInfo.guideData.guideDesc}}</p>
        <p class="c-fs20 c-fc-gray c-fw400 c-mt5" v-if="orderInfo.guideData.guideTitle != ''">{{orderInfo.guideData.guideTitle}}</p>
        <div class="c-ww160 c-hh160 c-mt20 c-mb10">
          <img class="c-w100 c-h" :src="$addXossFilter(orderInfo.guideData.guideQrcode)" alt="">
        </div>
        <p class="c-fs20 c-fc-gray c-fw400">长按二维码识别，或保存截图</p>
      </div>
    </div>
    <cj-popup v-model="showCoup" round position="bottom" :closeable="true" title="选择优惠券">
      <div class="c-flex-column c-pb40 c-bg-coupon c-maxw640">
        <div class="c-fs22 c-fc-sblack c-fw500 c-pt28 c-pb8 c-ph24">当前商品可用的优惠券</div>
        <div class="all-coupon-bg c-ph24 c-pt10 c-contexty-scroll">
          <coupon-item-com v-for="(item, index) in enableCoupon" :key="index" :couponInfo="item" :showFooter="false" @clickCouponItem="clickCoupon(item, index)" class="c-mb20 "
            v-show="item.amount * 1 <= showPrice * 1"
          >
            <div @click.stop="clickCoupon(item, index)" :class="item.rcdId == choosedCouponId ? 'theme-fc' : 'c-fc-sgray'" class="iconfont c-fs28 c-pa c-p-t64 c-p-r24">&#xe796;</div>
          </coupon-item-com>
        </div>
      </div>
    </cj-popup>
    <!-- <div class="c-h" v-show="showCoup">
      <div class="masker" @click="closeCoupon"></div>
      <div class="content c-flex-column c-pb40 c-bg-coupon c-maxw640">
        <div class="c-flex-row c-flex-center c-w100 c-hh80 c-fs28 c-fc-xblack c-bg-white">选择优惠券</div>
        <div class="close" @click="closeCoupon"><span class="iconfont c-fs24 c-fc-gray">&#xe61b;</span></div>
        <div class="c-fs20 c-fc-gray c-pv20 c-ph24">当前商品可用的优惠券</div>
        <div class="all-coupon-bg c-maxh600 c-ph24 c-pt10 c-contexty-scroll">
          <coupon-item-com v-for="(item, index) in enableCoupon" :key="index" :couponInfo="item" :showFooter="false" @clickCouponItem="clickCoupon(item, index)" class="c-mb20 "
            v-show="item.amount * 1 <= showPrice * 1"
          >
            <div @click.stop="clickCoupon(item, index)" :class="item.rcdId == choosedCouponId ? 'theme-fc' : 'c-fc-gray'" class="iconfont c-fs28 c-pa c-p-t64 c-p-r24">&#xe6b1;</div>
          </coupon-item-com>
        </div>
      </div>
    </div> -->
    <!-- 赠送礼包 -->
    <vip-present-com :gift="good.gift" :showPresent="showPresent" @goPresent="goPresent" @goMyValueVoucher="goMyValueVoucher" @goMyPointDetail="goMyPointDetail"
      @closePresent="closePresent"></vip-present-com>
    <!-- 推荐有礼 -->
    <recommend-present
      ref="recommendPresent"
      from="vipBuy"
      @setSuccessRecommendFlag="setSuccessRecommendFlag"
      @paySuccessCallBack="paySuccessCallBack"
    ></recommend-present>
    <!-- 填写收货信息 -->
    <cj-popup v-model="isShowAddressInfo" round title="收货地址" class="c-w80">
      <div class="c-ph40">
        <div class="c-fs20 c-fc-sblack c-flex-row c-aligni-center c-justify-center">
          <div class="iconfont c-fs22 c-fc-sorange c-mr10">&#xe7e6;</div>
          <div>请填写收货人信息，便于我们给您寄送实物</div>
        </div>
        <div class="c-fs24 c-fc-xblack c-w100 c-flex-row c-aligni-center c-hh70 c-bd-b1-f5 c-p c-mt10">
          <input ref="inputGrop1" type="text" v-model="name" :class="isEmpty? 'invalid':''" :placeholder="isEmpty?'*请填写收货人':'收货人'"
            class="c-textAlign-l c-fs24 c-bd0 c-flex-grow1 c-w0 c-fc-xblack c-hh60 c-flex-row c-flex-center" />
          <div class="iconfont c-fs20 c-fc-sgray c-ml10" v-show="name && name.length > 0" @click="clearInputValue('name')">&#xe6ec;</div>
        </div>
        <div class="c-fs24 c-fc-xblack c-w100 c-flex-row c-aligni-center c-hh70 c-bd-b1-f5">
          <input ref="inputGrop2" type="number" v-model="mobile" :class="isEmpty? 'invalid':''" :placeholder="isEmpty?'*请填写正确的联系电话':'联系电话'"
            class="c-textAlign-l c-fs24 c-bd0 c-flex-grow1 c-w0 c-fc-xblack c-hh60 c-flex-row c-flex-center" />
          <div class="iconfont c-fs20 c-fc-sgray c-ml10" v-show="mobile && mobile.length > 0" @click="clearInputValue('mobile')">&#xe6ec;</div>
        </div>
        <div class="c-fs24 c-fc-xblack c-w100 c-flex-row c-aligni-center c-justify-sb c-hh70 c-bd-b1-f5">
          <group ref="inputGrop3" class="c-w100 c-textAlign-r c-pz100 addressSelected" :class="isEmpty ? 'invalid' : ''">
            <x-address :themeColor="$getThemeColor()" :popup-style="{'z-index':'100000','max-height':'42%'}" value-text-align="left" title="" @on-show="showAddress = true"
              @on-hide="showAddress = false" @on-shadow-change="onShadowChange" v-model="addressSelected" :list="addressDataList" raw-value :placeholder="isEmpty?'*请填写所在地区':'所在地区'"
              :show.sync="showAddress" class="c-flex-grow1">
            </x-address>
          </group>
          <div class="iconfont c-fs18 c-fc-sgray">&#xe908;</div>
        </div>
        <div class="c-fs24 c-fc-xblack c-w100 c-flex-row c-aligni-center c-hh70 c-bd-b1-f5">
          <input ref="inputGrop4" type="text" v-model="addressDetail" :class="isEmpty ? 'invalid' : ''" :placeholder="isEmpty?'*请填写详细地址':'详细地址'"
            class="c-textAlign-l c-fs24 c-bd0 c-flex-grow1 c-w0 c-fc-xblack c-hh60 c-flex-row c-flex-center" />
          <div class="iconfont c-fs20 c-fc-sgray c-ml10" v-show="addressDetail && addressDetail.length > 0" @click="clearInputValue('addressDetail')">&#xe6ec;</div>
        </div>
      </div>
      <div class="c-flex-row c-w100 c-aligni-center c-justify-center c-mt30 c-mb30">
        <div @click="submitAddressInfo" class="c-fs22 c-fc-white c-ww220 c-hh50 c-flex-row c-aligni-center c-justify-center c-br30 knowBtn">
          <div>下一步</div>
        </div>
      </div>
    </cj-popup>
    <add-address-modal v-if="hasGoodsGiftNew" :open-add-address.sync="showAddressModal" :edit-address-id="currentAddress ? currentAddress.addrId : 0" @selectAddr="selectAddr" @closeAddAddress="showAddressModal = false"></add-address-modal>
    <!-- 开票 -->
    <invoice-modal ref="invoiceModal" :showInvoice="showInvoice" @getInvoice="getInvoice" @clickCloseModal="clickCloseModal"></invoice-modal>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js";
import { checkEnableModule } from "@/utils/checkEnableModuleUtil.js";
import PayPassword from "@/components/templates/common/pay/payPassword.vue";
import VipCustomImg from "@/components/templates/common/VipCustomImg.vue";
import vipPresentCom from "@/components/templates/common/vipPresentCom.vue";
import VipTemplate from "@/components/templates/vipTemplate.vue";
import PayAndVip from "@/components/templates/common/pay/payAndVip.vue";
import recommendPresent from '@/components/templates/recommendPresent';
import couponItemCom from "@/components/templates/couponItemCom.vue";
import addAddressModal from '@/components/templates/addAddressModal';
import InvoiceModal from "@/components/templates/invoiceModal.vue";
import { mapState } from 'vuex';
import { XSwitch, XAddress } from 'ckjrweb-mp-ui/src/components/index';
import { getBindPhoneSetting } from "@/utils/checkUnBindPhone.js";
let isFromAllOrderList = false;
let isWechatPaying = false;
let isGoPresent = false;
let flashCkFromOld = {
  //后台将限时购的prodType进行整合，所以限时购前端传给后台的prodType要进行转化
  "66": global.ckFrom.course,
  "67": global.ckFrom.column,
  "68": global.ckFrom.vip,
  "69": global.ckFrom.svip,
  "70": global.ckFrom.package,
  "71": global.ckFrom.exam,
  "72": global.ckFrom.live,
  "73": global.ckFrom.presentVip,
  "74": global.ckFrom.presentSvip,
  "8075": global.ckFrom.clockIn,
  "8076": global.ckFrom.camp,
  "8077": global.ckFrom.social,
  "8078": global.ckFrom.reservation,
  "8079": global.ckFrom.voiceTest,
  "8080": global.ckFrom.mutuaTest,
  "8081": global.ckFrom.activity,
  "8083": global.ckFrom.ebooks,
  "8084": global.ckFrom.privateClass,
};
let collageCkFromOld = {
  //后台将拼团的prodType进行整合，所以拼团前端传给后台的prodType要进行转化
  "30": global.ckFrom.course,
  "29": global.ckFrom.column,
  "36": global.ckFrom.activity,
  "31": global.ckFrom.vip,
  "32": global.ckFrom.svip,
  "48": global.ckFrom.package,
  "104": global.ckFrom.distributionColumnPay,
  "124": global.ckFrom.live,
  "9078": global.ckFrom.camp,
  "9010": global.ckFrom.social,
  "9041": global.ckFrom.clockIn,
  "9042": global.ckFrom.itemBank,
  "9043": global.ckFrom.edu,
  "9044": global.ckFrom.ebooks,
  "9045": global.ckFrom.personalLive,
};
export default {
  name: "VipBuy",
  components: {
    PayPassword,
    XSwitch,
    VipCustomImg,
    VipTemplate,
    XAddress,
    vipPresentCom,
    PayAndVip,
    recommendPresent,
    couponItemCom,
    addAddressModal,
    InvoiceModal
  },
  props: [],
  beforeCreate() { },
  data() {
    return {
      customPointName: localStorage.getItem("customPointName"),
      theme: localStorage.getItem("colorName")
        ? localStorage.getItem("colorName")
        : "mb5_default",
      cfrom: global.ckFrom,
      userId: null,
      userName: localStorage.getItem("userName"),
      balance: 0, // 账户余额
      showPassword: false, // 是否显示输入支付密码
      totalPrice: 0, // 总价
      showPrice: 0, // 标签价
      good: { cover: { coverUrl: '' }, gift: {} }, //vip商品
      payType: -1, // -1默认选取任何方式（所有方式都加了开关，有可能会关掉所有支付方式 0是微信支付，1是余额支付，2是虚拟币支付
      password: "", // 输入的密码
      vId: -1, // 选择的类型id cmpId赋值
      vipType: 2, // vip 类型 2:vip,4:svip
      memberInfo: { rmb2Points: 0 },
      isShowReNew: 0, //是否显示续费相关
      showDiscountPoints: false, //是否显示积分抵扣
      isUserPoints: 0, //是否开启积分抵扣，0：关闭 1：开启
      payPwd: true, // 是否设置了密码
      orderId: "", // 生成的订单id
      isSubmit: true, //防止多次提交
      isShowQr: false, // 是否显示公众号二维码
      gzhQrCode: '', // 公众号图片
      subscribe: 1, // 是否关注了公众号
      isiOS: false,
      showCouponBtn: false,
      showCoup: false,
      enableCoupon: [],
      unableCoupon: [],
      choosedCouponPrice: 0.00,
      choosedCouponDiscount: 1, //折扣券的折扣
      choosedCouponIndex: -1,
      choosedCouponId: -1,
      pId: null,
      groupId: null, //拼团的groupId
      amount: 0.00,
      showPresent: false,
      ptFrom: 0,
      presentList: '', //亲情卡赠送的内容
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      rewardPoints: 0,
      showPoints: false,
      isActivity: 0, //是否参加推荐购买会员活动,
      getRecommendGiftFlag: false, //是否领取了推荐购买会员的推荐礼包
      isFrom: 0,
      consigneeData: null, // 升级会员是有实物赠送的收货地址
      isShowAddressInfo: false,
      showAddress: false,
      name: '',
      mobile: '',
      addressSelected: [],
      consigneProvinceId: '',
      consigneeCityId: '',
      consigneeAreaId: '',
      address: '',
      addressDetail: '',
      addressDataList: [],
      isEmpty: false,
      orderInfo: null, // 入群引导信息
      isCheckAgreement: true,
      enableProtocol: 0,
      enableProtocolWxPayment: 0,
      enableProtocolAppPayment: 0,
      isProtocolWx: 0, // 移动端是否展示vip协议，1是，0否
      isProtocolPc: 0, // pc扫的链接是否展示vip协议，1是，0否
      protocolInfo: null, // 协议信息
      attendId: '', //砍价购id
      pathFrom: '', //上一级页面的路径
      isSubMch: 0, //1是服务商二级商户， 0普通商户
      remainderPrice: 0,
      bindPhoneSetting: null,
      groupBuyNum: 0,
      groupBuyId: 0,
      groupTotalPrice: 0,
      enablePayMember: null,
      giftCardName: '',
      giftCardPic: '',
      giftCardInfo: {}, //虚拟币的信息数据
      totalCoin: 0, // 该产品所需要的虚拟币个数
      enableGiftCard: false, // 是否可以使用虚拟币支付
      payConf: null,
      showPayAndVip: false,
      chainInfo: '',
      hasGoodsGiftNew: false, // 新版礼包的实体商品从商城中选取
      hasGoodsGiftOld: false, // 旧版礼包的实体商品是自定义的 新旧填写地址的方式不一致，不好兼容，所以区分开来
      currentAddress: '',
      showAddressModal: false,
      isInvoice: -1,
      invoiceInfo: null, // 开票信息
      showInvoice: false, //开发票弹窗
    };
  },
  beforeRouteEnter(to, from, next) {
    if (from.path == '/member/myOrder/allOrderList' || from.path == '/member/myOrder/knowledgeOrderDetail') {
      isFromAllOrderList = true;
    }
    next(vm => {
      if (!(to.query.isGoldPlan && to.query.isGoldPlan == 1 && localStorage.getItem("shopPayBack"))) {
        vm.pathFrom = from.fullPath;
      }
      // 只有从特定几个页面过来的才需要判断是否有缓存vip订单数据并显示
      if (localStorage.getItem("vipOrderInfo") && (from.path == '/member/presentCourse/presentCourseList' || from.path == '/member/myValueVoucher/myValueVoucher' || from.path == '/member/myIntegral/integralDetail')) {
        vm.isShowPolitely = true;
        vm.orderInfo = JSON.parse(localStorage.getItem("vipOrderInfo"));
      } else {
        vm.isShowPolitely = false;
        localStorage.removeItem("vipOrderInfo")
      }
    });
  },
  created() {
    utilJs.appShare(this);
    if (utilJs.isIOSAnonUser()) {
      window.localStorage.clear();
      window.webkit.messageHandlers.iosWechatLoginOut.postMessage('loginOut');
    }
  },
    computed: {
    ...mapState({
      allOrderList: state => state.oem_store.allOrderList,
    }),
    // 判断是否显示积分、优惠券、链动、发票等优惠信息
    isShowPriceInfo() {
      return this.isShowChainInfo || this.isShowSelectCoupon || this.isShowUsePoint || (this.isInvoice == 1 && this.payType != 2)
    },
    // 判断是否显示链动优惠信息
    isShowChainInfo() {
      return !(this.isShowReNew && this.good.duration > 0) && this.chainInfo && this.chainInfo.isChainProd && Number(this.chainInfo.chainDiscountPrice) > 0 && Number(this.chainInfo.chainDiscountPrice) < Number(this.showPrice)
    },
    // 判断是否显示选择优惠券
    isShowSelectCoupon() {
      return this.showCouponBtn && (this.payType != 2 || (this.payType == 2 && !this.giftCardInfo.unableMarketing))
    },
    // 判断是否显示积分抵扣
    isShowUsePoint() {
      return this.showDiscountPoints && this.memberInfo.rmb2Points != null &&
              (this.ptFrom != this.cfrom.flashSalesVip && this.ptFrom != this.cfrom.flashSalesSvip && this.ptFrom != this.cfrom.collageVip && this.ptFrom != this.cfrom.collageSvip) &&
              !this.pId && this.isFrom != 4 && (this.payType != 2 || (this.payType == 2 && !this.giftCardInfo.unableMarketing))
    },
    //赠送会员
    isFromPresent() {
      let result = this.ptFrom == global.ckFrom.presentVip || this.ptFrom == global.ckFrom.presentSvip ||
        this.ptFrom == global.ckFrom.flashSalesPresentVip || this.ptFrom == global.ckFrom.flashSalesPresentSvip;
      return result;
    },
    isHasVipPermission() {
      const agentTypeArr = [3, 5, 6, 7, 8];
      //服务商身份 || svip永久免费 || vip永久免费  （企业团购不管有没有权限，都可以再购买）
      let hasPermission = this.isFrom == 4 ?
        false
        : ((this.memberInfo.vipType && agentTypeArr.includes(this.memberInfo.vipType * 1)) ||
          (this.memberInfo.svipEndTime && this.memberInfo.svipEndTime.split(' ')[0] == '9999-12-31') ||
          (this.vipType == 2 && this.memberInfo.vipEndTime && this.memberInfo.vipEndTime.split(' ')[0] == '9999-12-31'));
      return hasPermission;
    },
    isShowProtocol() {
      //开启协议 && （（app开启 && app环境） || （公众号开启 && 非app环境））
      const isAndroidApp = utilJs.isAndroidApp();
      const isiOSApp = utilJs.isIOSAppALL();
      let result = this.enableProtocol == 1 && ((this.enableProtocolAppPayment == 1 && (isAndroidApp || isiOSApp)) || (this.enableProtocolWxPayment == 1 && !isAndroidApp && !isiOSApp));
      return result;
    },
    couponNumber() {
      let num = 0;
      num = this.enableCoupon.filter(item => (item.amount * 1 <= this.showPrice)).length;
      return num;
    },
  },
  watch: {
    password: function () {
      if (this.password && isNaN(this.password)) {
        this.password = "";
      } else {
        this.password.length > 6 && this.password.substr(0, 6);
      }
    }
  },
  mounted() { },
  methods: {
    // 关闭开票弹窗
    clickCloseModal() {
      this.showInvoice = false;
    },
    //显示发票弹窗
    clickShowInvoice() {
      this.showInvoice = true;
      this.$refs.invoiceModal.public_initData(this.invoiceInfo);
    },
    // 获取开票信息
    getInvoice(data) {
      this.showInvoice = false;
      this.invoiceInfo = data;
    },
    setSuccessRecommendFlag(flag) {
      this.getRecommendGiftFlag = flag == 1 ? true : false;
    },
    clickPayType(payType) {
      this.payType = payType;
    },
    //计算支付虚拟币总额
    _calcCoin() {
      if (this.enableGiftCard) {
        if (this.giftCardInfo.unableMarketing) {
          //不叠加
          this.totalCoin = Math.ceil((this._sellingPrice * Number(this.memberInfo.proportion)).toFixed(2));
        } else {
          //叠加
          this.totalCoin = Math.ceil(this.totalPrice * Number(this.memberInfo.proportion).toFixed(2));
        }
      }
    },
    groupBuyChange(groupBuyInfo) {
      this.groupBuyNum = groupBuyInfo.groupBuyNum;
      this.groupBuyId = groupBuyInfo.groupBuyId;
      this.groupTotalPrice = groupBuyInfo.groupTotalPrice;
      this.totalPrice = this.groupTotalPrice
    },
    // 获取vip服务协议
    getProdProtocol() {
      this.isProtocolWx = false;
      this.isProtocolPc = false;
      let type = 1;
      if ((this.ptFrom == this.cfrom.flashSalesPresentVip) || (this.ptFrom == this.cfrom.presentVip) || (this.ptFrom == this.cfrom.flashSalesVip) || (this.ptFrom == this.cfrom.vip) || (this.ptFrom == this.cfrom.collageVip)) {
        type = 1;
      } else if ((this.ptFrom == this.cfrom.flashSalesPresentSvip) || (this.ptFrom == this.cfrom.presentSvip) || (this.ptFrom == this.cfrom.flashSalesSvip) || (this.ptFrom == this.cfrom.svip) || (this.ptFrom == this.cfrom.collageSvip)) {
        type = 23;
      }
      this.getPayProtocol(type);
    },
    getPayProtocol(prodType) {
      utilJs.getMethod(`${global.apiurl}protocols/getProtocolByProdType?prodType=${prodType}`, (res) => {
        this.protocolInfo = res.protocol && res.protocol.length > 0 ? res.protocol : null;
        this.isCheckAgreement = res.relatesType == 1 ? true : false;
      });
    },
    clickProtocol(item) {
      this.$routerGo(this, "push", { path: `/homePage/agent/protocolInfo`, query: { protocolId: item.protocolId } });
    },
    handleClickDetail() {
      let type = 1; // 默认跳转回会员中心
      if (this.pathFrom && this.pathFrom.includes('vipDetail')) {
        type = 2; // 从会员详情来的就会会员详情
      }
      this.$routerGo(this, "push", {
        path: `/member/vip/${type == 2 ? 'vipDetail' : 'vipUp'}?type=${this.ptFrom}`
      });
    },
    // 判断是否入群引导
    getGuideData() {
      let _this = this;
      let type = (this.ptFrom == global.ckFrom.collageVip ? global.ckFrom.vip : this.ptFrom == global.ckFrom.collageSvip ? global.ckFrom.svip : this.ptFrom == global.ckFrom.flashSalesVip ? global.ckFrom.vip : (this.ptFrom == global.ckFrom.flashSalesSvip ? global.ckFrom.svip : this.ptFrom == global.ckFrom.flashSalesPresentVip ? global.ckFrom.presentVip : this.ptFrom == global.ckFrom.flashSalesPresentSvip ? global.ckFrom.presentSvip : this.ptFrom));
      utilJs.getMethod(global.apiurl + 'common/getGuideData?prodId=' + this.vId + '&prodType=' + type, function (res) {
        if (res.isNeedShowPayPage == 1) {
          _this.getGuideOrderInfo();
        } else {
          _this.paySuccessCallBackCon();
        }
      },
        failRes => {
          _this.paySuccessCallBackCon();
        }
      );
    },
    // 获取入群引导，
    getGuideOrderInfo() {
      let _this = this;
      utilJs.getMethod(global.apiurl + 'common/getGuideOrderInfo?orderId=' + this.orderId, function (res) {
        _this.orderInfo = res;
        if (_this.orderInfo.guideData.isOpenGuide == 1 && _this.orderInfo.guideData.guideType.includes(2)) {
          _this.isShowPolitely = true;
          _this.isShowQr = false;
        } else {
          _this.paySuccessCallBackCon();
        }
      },
        failRes => {
          _this.paySuccessCallBackCon();
        }
      );
    },
    getAddress() {
      if (this.isFrom != 4 && this.good.isFreeGood == 1 && this.good.giftRelates && this.good.giftRelates.length > 0) {
        utilJs.getMethod(global.apiurl + 'address?page=1', res => {
          this.currentAddress = res.address.data && res.address.data.length > 0 ? res.address.data[0] : '';
          this.$nextTick(() => {
            this.hasGoodsGiftNew = true;
            this.hasGoodsGiftOld = false;
          });
        });
      } else if (this.isFrom != 4 && this.good.isFreeGood == 1 && this.good.freeGoodName) {
        this.hasGoodsGiftNew = false;
        this.hasGoodsGiftOld = true;
      } else {
        this.hasGoodsGiftNew = false;
        this.hasGoodsGiftOld = false;
      }
    },
    getAddressData() {
      utilJs.getMethod(`${global.apiurl}common/getAreaListForAgent`, res => {
        this.addressDataList = res.data;
      }, failRes => {
      });
    },
    selectAddr(addrInfo) {
      this.currentAddress = addrInfo;
    },
    popAddAddress() {
      this.showAddressModal = true;
    },
    // 获取选中地址
    onShadowChange(ids, names) {
      this.consigneProvinceId = ids[0];
      this.consigneeCityId = ids[1];
      this.consigneeAreaId = ids[2];
      this.address = names[0] + names[1] + names[2];
    },
    // 清除输入框内容
    clearInputValue(val) {
      if (val == "name") {
        this.name = '';
      } else if (val == 'mobile') {
        this.mobile = '';
      } else {
        this.addressDetail = '';
      }
    },
    // 提交收货信息
    submitAddressInfo() {
      if (this.name == '' || this.mobile.length == 0 || this.mobile.length != 11 || this.addressSelected.length == 0 || this.addressDetail == '') {
        if (this.mobile.length != 11) {
          this.mobile = '';
        }
        this.isEmpty = true;
        return;
      }
      this.consigneeData = {};
      this.consigneeData.consigneeAddress = this.addressDetail;
      this.consigneeData.consigneeName = this.name;
      this.consigneeData.consigneePhone = this.mobile;
      this.consigneeData.consigneProvinceId = this.consigneProvinceId;
      this.consigneeData.consigneeCityId = this.consigneeCityId;
      this.consigneeData.consigneeAreaId = this.consigneeAreaId;
      this.consigneeData.consigneeArea = this.address;
      this.isEmpty = false;
      this.clickBuy();
    },
    //赠送会员的选择vip
    chooseVip(vipInfo) {
      this.choosedCouponIndex = -1;
      this.choosedCouponId = -1;
      this.choosedCouponPrice = 0.00;
      this.choosedCouponDiscount = 1;
      this.amount = 0.00;
      this.vId = vipInfo.vId;
      this.pId = vipInfo.pId;
      this.ptFrom = vipInfo.ptFrom;
      this.vipType = vipInfo.vipType;
      this.ckFrom = vipInfo.ckFrom;

      this.isShowQr = false;
      this.showDiscountPoints = false;
      this.showCouponBtn = false;
      this.showCoup = false;
      this.enableCoupon = [];
      this.unableCoupon = [];
      this.choosedCouponPrice = 0.00;
      this.choosedCouponIndex = -1;
      this.choosedCouponId = -1;
      this.showPresent = false;
      this.getRecommendGiftFlag = false;
      this.presentList = '';
      this.rewardPoints = 0;
      this.showPoints = false;
      this.showPrice = 0;
      this.totalPrice = 0;
      this.good = { cover: { coverUrl: '' }, gift: {} };
      this.isUserPoints = 0;
      this.remainderPrice = 0;
      this.getProdProtocol();
      this.payShow(this.ckFrom, this.pId);
    },
    // 跳转积分明细
    goPoint() {
      this.$routerGo(this, "push", {
        path: `/member/myIntegral/integralDetail?tabIndex=-1`
      });
    },
    //计算积分抵扣
    getDeductible() {
      if (!this.good.cmpId || !this.memberInfo.userPoints || Math.floor(this.memberInfo.userPoints) == 0 || !this.memberInfo.enablePoints) {
        return 0;
      } else {
        let discount = Math.floor(100 * Number(Math.floor(this.memberInfo.userPoints)) / Number(this.memberInfo.rmb2Points)) / 100;
        let DeductiblePrice = Math.min(discount, this.good.deductiblePoints, Number(this.getShowPrice()), this.remainderPrice);
        if (DeductiblePrice <= 0) {
          DeductiblePrice = 0;
          this.isUserPoints = 0;
        }
        return DeductiblePrice.toFixed(2);
      }
    },
    // 应该展示的总价:活动价>购买价(赠送会员时)>新人价、新人价>续费价>购买价(虚拟币支付时没有活动价)
    getShowPrice() {
      // 是否显示营销价格（虚拟币改成营销活动直接不能使用，不过加了这个判断也不影响）
      let isMarketing = this.payType != 2 || (this.payType == 2 && this.enableGiftCard && this.giftCardInfo && !this.giftCardInfo.unableMarketing);
      if (this.isFrom == 4 && isMarketing) {
        return this.groupTotalPrice;
      } else if ((this.ptFrom == this.cfrom.flashSalesVip ||
        this.ptFrom == this.cfrom.flashSalesSvip ||
        this.ptFrom == this.cfrom.collageVip ||
        this.ptFrom == this.cfrom.collageSvip ||
        this.ptFrom == this.cfrom.flashSalesPresentVip ||
        this.ptFrom == this.cfrom.flashSalesPresentSvip) && isMarketing) {
        return Number(this.good.sales.price).toFixed(2);
      } else if (this.attendId && this.good.bargain && isMarketing) {
        return Number(this.good.bargain.price).toFixed(2);
      } else if (this.recRelateId && this.recType == 3) {
        return Number(this.good.price).toFixed(2)
      } else if (this.ptFrom == this.cfrom.presentVip || this.ptFrom == this.cfrom.presentSvip) {
        return Number(this.good.price).toFixed(2);
      } else if (this.good.isNewUser && this.good.newUserPrice) {
        return Number(this.good.newUserPrice).toFixed(2);
      } else if (this.good.isRenew && this.good.isSetRenew == 1 && this.good.renewRate !== null && this.ptFrom != this.cfrom.presentVip && this.ptFrom != this.cfrom.presentSvip && this.ptFrom != this.cfrom.flashSalesPresentVip && this.ptFrom != this.cfrom.flashSalesPresentSvip) {
        return Number(this.good.price * this.good.renewRate / 100).toFixed(2);
      } else {
        return Number(this.good.price).toFixed(2);
      }
    },
    //展示持有的优惠券
    showCoupon() {
      this.showCoup = true;
    },
    //关闭展示的优惠券
    closeCoupon() {
      this.showCoup = false;
    },
    //计算支付金额
    changeSwitch: function () {
      let p = Number(this.showPrice);
      if (!(this.isShowReNew && this.good.duration > 0) && this.chainInfo && this.chainInfo.isChainProd && Number(this.chainInfo.chainDiscountPrice) > 0 && Number(this.chainInfo.chainDiscountPrice) < Number(this.showPrice)) {
        p = Number(this.chainInfo.chainDiscountPrice);
      }
      //积分抵扣的金额
      // let jp =
      //   this.isUserPoints == 1
      //     ? this.getDeductible()
      //     : 0;
      // 积分抵扣后的金额
      // let jip = Number(p);
      //针对满减优惠券判断已选中的优惠券是否符合满减规则
      let choosedCoup = this.enableCoupon.find((value, index, arr) => { return value.rcdId == this.choosedCouponId });
      if (this.choosedCouponId && this.choosedCouponId > 0 && this.enableCoupon && choosedCoup && (choosedCoup.type == 3 || choosedCoup.type == 5) && choosedCoup.subType == 2) {
        if (Number(choosedCoup.amount) > p) {
          this.choosedCouponIndex = -1;
          this.choosedCouponId = -1;
          this.choosedCouponPrice = 0.00;
          this.choosedCouponDiscount = 1;
          this.amount = 0.00;
        }
      }
      //总价格
      if (this.choosedCouponDiscount < 1) {
        let isDiscount = !!choosedCoup.enableTotalAmount && (Number(1 - this.choosedCouponDiscount) * p > choosedCoup.totalAmount)
        this.remainderPrice = isDiscount ? Number(p - Number(choosedCoup.totalAmount)) : Number(p * this.choosedCouponDiscount)
        let jp =
          this.isUserPoints == 1
            ? this.getDeductible()
            : 0;
        this.totalPrice = Number(this.remainderPrice - jp).toFixed(2) > 0 ? Number(this.remainderPrice - jp).toFixed(2) : 0.00;
        this.choosedCouponPrice = (p - this.totalPrice - jp).toFixed(2) > 0 ? (p - this.totalPrice - jp).toFixed(2) : 0.00;
      } else {
        this.remainderPrice = Number(p - Number(this.choosedCouponPrice));
        let jp =
          this.isUserPoints == 1
            ? this.getDeductible()
            : 0;
        this.totalPrice = Number(p - Number(this.choosedCouponPrice) - jp).toFixed(2) > 0 ? Number(p - Number(this.choosedCouponPrice) - jp).toFixed(2) : 0.00;
      }
      // 根据金额过滤可用优惠券
      this.resetCoupon(p);
      this._calcCoin();
    },
    // 点击支付
    clickBuy(e) {
      // 没有选中支付方式
      if (this.payType == -1) {
        return
      }
      // 小程序环境不能跳充值页面
      if (this.payType == 2 && this.totalCoin > this.memberInfo.coinAmount && this.$isWxApp()) {
        return
      }
      if (this.payType == 2 && this.totalCoin > this.memberInfo.coinAmount) {
        // 选择虚拟币支付，且虚拟币余额不足，则跳到虚拟币充值页面
        let query = this.$route.query || {};
        query.isComeFrom = 'vipBuy';
        sessionStorage.setItem('giftCardBack', JSON.stringify(query))
        this.$routerGo(this, "replace", { path: "/member/giftCard/rechargeCard"});
        return;
      }
      //未设置密码 && 余额支付 && 支付价格不为0
      if (this.memberInfo.hasPassword == 0 && this.payType == 1 && Number(this.totalPrice) != 0) {
        this.$routerGo(this, "push", { path: "/member/scholarship/updatePassword" });
        return;
      }
      if (!this.isCheckAgreement && this.protocolInfo) {
        this.$showCjToast({
          text: "请先同意相关协议！",
          type: "warn",
        })
        return;
      }
      if (this.isFrom != 4 && this.good.isFreeGood == 1 && this.isShowAddressInfo == false && this.hasGoodsGiftOld) {
        if (this.consigneeData != null) {
          this.name = this.consigneeData.consigneeName;
          this.mobile = this.consigneeData.consigneePhone;
          this.addressDetail = this.consigneeData.consigneeAddress;
          this.consigneProvinceId = this.consigneeData.consigneProvinceId != null ? this.consigneeData.consigneProvinceId + '' : '';
          this.consigneeCityId = this.consigneeData.consigneeCityId != null ? this.consigneeData.consigneeCityId + '' : '';
          this.consigneeAreaId = this.consigneeData.consigneeAreaId != null ? this.consigneeData.consigneeAreaId + '' : '';
          this.addressSelected = this.consigneProvinceId != '' ? [this.consigneProvinceId, this.consigneeCityId, this.consigneeAreaId] : [];
        }
        this.getAddressData();
        this.isShowAddressInfo = true;
        return;
      }
      this.isShowAddressInfo = false;

      if (this.hasGoodsGiftNew && !this.currentAddress && this.hasGoodsGiftNew) {
        this.$showCjToast({
          text: '请选择收货地址',
          type: 'warn',
        });
        return;
      }
      if (this.isSubmit) {
        this.isSubmit = false;
        let data = {
          prodId: this.vId,
          payMoney: (this.payType == 2 && this.giftCardInfo.unableMarketing) ? (this._sellingPrice) : Number(this.totalPrice).toFixed(2),
          prodType: this.ptFrom == global.ckFrom.collageVip ? global.ckFrom.vip : this.ptFrom == global.ckFrom.collageSvip ? global.ckFrom.svip : this.ptFrom == global.ckFrom.flashSalesVip ? global.ckFrom.vip : (this.ptFrom == global.ckFrom.flashSalesSvip ? global.ckFrom.svip : this.ptFrom == global.ckFrom.flashSalesPresentVip ? global.ckFrom.presentVip : this.ptFrom == global.ckFrom.flashSalesPresentSvip ? global.ckFrom.presentSvip : this.ptFrom),
          usePoint: (this.payType == 2 && this.giftCardInfo.unableMarketing) ? 0 : this.isUserPoints,
          fromInvite: 0,
          payMethod: this.payType == 2 ? 14 : (this.payType == 0 ? 1 : (this.payType == 3 ? 20 : 2)), //payMethod 1微信，2余额，14虚拟币， 20支付宝
          useCoupon: (this.payType == 2 && this.giftCardInfo.unableMarketing) ? 0 : this.choosedCouponId,
          isActivity: 0 //this.isActivity
        };
        if (this.ptFrom == global.ckFrom.flashSalesVip || this.ptFrom == global.ckFrom.flashSalesSvip || this.ptFrom == global.ckFrom.flashSalesPresentVip || this.ptFrom == global.ckFrom.flashSalesPresentSvip) {
          data.mtkType = 1;
        }
        if (this.ptFrom == global.ckFrom.collageVip || this.ptFrom == global.ckFrom.collageSvip) {
          data.mtkType = 2;
        }
        if (this.consigneeData && this.consigneeData != null && this.hasGoodsGiftOld) {
          data.consigneeAddress = this.consigneeData.consigneeAddress;
          data.consigneeName = this.consigneeData.consigneeName;
          data.consigneePhone = this.consigneeData.consigneePhone;
          data.consigneProvinceId = this.consigneeData.consigneProvinceId;
          data.consigneeCityId = this.consigneeData.consigneeCityId;
          data.consigneeAreaId = this.consigneeData.consigneeAreaId;
          data.consigneeArea = this.consigneeData.consigneeArea;
        }
        if (this.hasGoodsGiftNew && this.currentAddress && this.hasGoodsGiftNew) {
          data.consigneeName = this.currentAddress.name;
          data.consigneePhone = this.currentAddress.mobile;
          data.consigneeAddress = this.currentAddress.province + this.currentAddress.city + this.currentAddress.area + this.currentAddress.address;
          data.consigneeAddressId = this.currentAddress.addrId;
          data.consigneeArea = this.currentAddress.province + this.currentAddress.city + this.currentAddress.area;
          data.consigneProvinceId = this.currentAddress.provinceId;
          data.consigneeCityId = this.currentAddress.cityId;
          data.consigneeAreaId = this.currentAddress.areaId;
        }
        if (this.pId) {
          data.groupId = this.pId; //限时购groupId
        }
        if (this.attendId) {
          data.groupId = this.attendId; //限时购groupId
          data.mtkType = 12;
        }
        if (this.recType == 3 && this.recRelateId) {
          data.groupId = this.recRelateId;
          data.mtkType = 19;
          data.inviteId = this.refereeId;
        }
        if (this.$route.query.type == this.cfrom.collageSvip || this.$route.query.type == this.cfrom.collageVip) {
          data.groupId = this.$route.query.groupId;
          data.collageId = this.$route.query.collageId;
          if (this.$route.query.stepIndex) { //阶梯拼团
            data.stepIndex = this.$route.query.stepIndex;
          }
        }
        if (this.isActivity) {
          data.isActivity = 0; //1; //推荐购买会员
        }

        //如果是pc端进入这边进行升级会员的话
        if (this.$route.query.orderKey) {
          data.orderKey = this.$route.query.orderKey;
        }
        if (this.goodsRoomId) {
          data.subProdType = 51;
          data.subProdId = this.goodsRoomId;
        };
        if (this.$route.query.youjiTag) { //有迹--私人订制
          data.youjiTag = this.$route.query.youjiTag;
        }
        if (this.$route.query.pcUserId) {
          data.pcUserId = this.$route.query.pcUserId
        }
        if (this.isFrom == 4) { //企业拼团
          data.mtkType = 22;
          data.groupId = this.groupBuyId;
          data.number = this.groupBuyNum;
        }
        if (!(this.isShowReNew && this.good.duration > 0) && this.chainInfo && this.chainInfo.isChainProd && Number(this.chainInfo.chainDiscountPrice) > 0 && Number(this.chainInfo.chainDiscountPrice) < Number(this.showPrice)) {
          data.chainDiscountMoney = Number(this.showPrice) - Number(this.chainInfo.chainDiscountPrice)
        }
        let $this = this;
        if (sessionStorage.getItem('promotedAccountId')) {
          data.promotedAccountId = sessionStorage.getItem('promotedAccountId')
          localStorage.setItem('promotedAccountId', sessionStorage.getItem('promotedAccountId'))
        }
        if (this.invoiceInfo && this.payType != 2) {
          data.invoiceData = this.invoiceInfo;
        }
        //携带当前进入的时候的分享人id过去后端做数据分析
        const xTraceSid = sessionStorage.getItem('shareFromUserId') || '';
        if (xTraceSid) {
          data['x-trace-sid'] = xTraceSid;
        }
        utilJs.postMethod(global.apiurl + "orders/submitOrder", data, function (
          res
        ) {
          $this.isSubmit = true;
          $this.orderId = res.orderId;
          $this.isSubMch = $this.payType == 0 ? res.isSubMch : 0;
          $this._liveId = res.liveId || '';
          $this._playType = res.playType || '';
          $this._socialType = res.socialType || '';
          if (res.code == 201) {
            $this.$showCjToast({
              text: "购买成功",
              type: "success",
            }).then(() => {
              // 生成新得订单则去除状态订单号值
              $this.$store.commit('updateOrderDetailNo', '');
              if (isFromAllOrderList && $this.$route.query.orderId) {
                $this.updateStore();
              }
              if ($this.$route.query.youjiTag) { //有迹--私人订制
                $this.$routerGo($this, "replace", { path: "/member/myOrder/allOrderList" });
              } else {
                $this.paySuccessCallBack();
              }
            })
            return;
          }
          if ($this.payType == 2) {
            // 虚拟币支付
            $this.giftCardPay();
          } else if ($this.payType == 1) {
            // 余额支付
            // 是否设置了支付密码
            if ($this.payPwd) {
              // 设置了，显示输入密码框
              $this.showPassword = true;
            } else {
              // 显示去设置密码
              $this.showSetPwdTip();
            }
          } else if ($this.payType == 3) { // 支付宝支付
            utilJs.postMethod( global.apiurl + "payment/alipayConf", {orderId: $this.orderId}, (aliRes) => {
              // 生成新得订单则去除状态订单号值
              $this.$store.commit('updateOrderDetailNo', '');
              $this.$routerGo($this, "replace", { path: "/homePage/course/aliPayMiddlePage", query: {orderId: aliRes.orderNo} });
            });
          } else {
            $this.wePay();
          }
        }, function () {
          $this.isSubmit = true;
        });
      }
    },
    // 虚拟币支付
    giftCardPay() {
      if (this.orderId != -1) {
        let data = {
          orderId: this.orderId,
        };
        let $this = this;
        utilJs.postMethod(`${global.apiurl}payment/giftCardPay`, data, (res) => {
          $this.$showCjToast({
            text: "购买成功",
            type: "success",
          }).then(() => {
            // 生成新得订单则去除状态订单号值
            $this.$store.commit('updateOrderDetailNo', '');
            if (isFromAllOrderList && $this.$route.query.orderId) {
              $this.updateStore();
            }
            if ($this.$route.query.youjiTag) { //有迹--私人订制
              $this.$routerGo($this, "replace", { path: "/member/myOrder/allOrderList" });
            } else {
              $this.paySuccessCallBack();
            }
          });
        });
      } else {
        this.$showCjToast({
          text: "订单提交失败，请重新提交！",
          type: "warn",
        });
      }
    },
    updateStore() {
      if (this.$route.query.tabIndex != 0) {
        let allOrderList = this.allOrderList;
        allOrderList.forEach((item, index) => {
          if (item.orderId == this.$route.query.orderId) {
            this.$set(allOrderList[index], 'status', 1)
          }
        })
        this.$store.commit('updateAllOrderList', allOrderList);
      } else {
        sessionStorage.setItem('filterOrder', true);
        sessionStorage.setItem('filterOrderId', this.$route.query.orderId);
        let allOrderList = this.allOrderList.filter(item => item.orderId != this.$route.query.orderId);
        this.$store.commit('updateAllOrderList', allOrderList);
      }
      isFromAllOrderList = false;
    },
    yuePay: function () {
      if (this.orderId != -1 && this.password != "") {
        let data = {
          orderId: this.orderId,
          payPwd: this.password
        };
        if (sessionStorage.getItem('promotedAccountId')) {
          data.promotedAccountId = sessionStorage.getItem('promotedAccountId')
        }
        let $this = this;
        utilJs.yuePay(
          data,
          function () {
            let that = $this;
            $this.$showCjToast({
              text: "购买成功",
              type: "success",
            }).then(() => {
              if (isFromAllOrderList && $this.$route.query.orderId) {
                $this.updateStore();
              }
              if ($this.$route.query.youjiTag) { //有迹--私人订制
                $this.$routerGo(that, "replace", { path: "/member/myOrder/allOrderList" });
              } else {
                $this.paySuccessCallBack();
              }
            });
          },
          function () { }
        );
      } else {
        this.$showCjToast({
          text: "订单生成失败，请重新提交订单",
          type: "warn",
        });
      }
    },
    wePay: function () {
      if (this.orderId != -1) {
        let data = {
          orderId: this.orderId
        };
        let $this = this;
        let u = navigator.userAgent;
        let isAndroid = u.indexOf('APPLogin') > -1; //android终端
        let isiOS = u.indexOf('IOSLogin') > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1; //ios终端
        if (isAndroid == true || isiOS == true) {
          let backUrl = window.location.href.split("#")[0] + "#/member/myOrder/allOrderList";
          utilJs.appPay(data, 0, 0, 0, 1, backUrl);
        } else {
          let that = $this;
          if (isWechatPaying) {
            return;
          }
          isWechatPaying = true;
          let isWechatH5Pay = !utilJs.isWeiXin() && utilJs.isMobileUserAgent() && !utilJs.isIOSAppALL() && !utilJs.isAndroidApp();
          if (isWechatH5Pay) {
            let payFromPath = window.location.href.split("#")[0] + "#" + ($this.pathFrom || '/');
            localStorage.setItem("payFromPath", payFromPath);
            data.goUrl = window.location.href.split("#")[0] + "#" + $this.$route.fullPath + "&isWechatH5Pay=1";
          } else if ($this.isSubMch == 1) {
            data.goUrl = window.location.href.split("#")[0] + "#" + $this.$route.fullPath + "&isGoldPlan=1";
            if ($this.$route.query.youjiTag) { //有迹--私人订制
              data.goUrl = window.location.href.split("#")[0] + "#/member/myOrder/allOrderList?isGoldPlan=1"
            }
            let ls = {
              orderId: $this.orderId,
              isSubMch: $this.isSubMch,
              liveId: $this._liveId || '',
              goodsRoomId: $this.goodsRoomId || '',
              socialType: $this._socialType || '',
              playType: $this._playType || '',
              pathFrom: $this.pathFrom,
              gzhQrCode: $this.gzhQrCode,
              good: $this.good
            }
            localStorage.setItem("shopPayBack", JSON.stringify(ls));
          }
          if (sessionStorage.getItem('promotedAccountId')) {
            data.promotedAccountId = sessionStorage.getItem('promotedAccountId')
          }
          utilJs.wechatPay(
            data,
            function () {
              // 生成新得订单则去除状态订单号值
              $this.$store.commit('updateOrderDetailNo', '');
              isWechatPaying = false;
              if (that.$route.query.youjiTag) { //有迹--私人订制
                that.$routerGo(that, "replace", { path: "/member/myOrder/allOrderList" });
              } else {
                that.paySuccessCallBack();
              }
            },
            function () {
              isWechatPaying = false;
            }
          );
        }
      } else {
        this.$showCjToast({
          text: "订单生成失败，请重新提交订单",
          type: "warn",
        });
      }
    },
    //点金计划，检查是否直播带货，是的话支付成功要跳转回直播间
    checkLiveGoods(pathStr) {
      let path = pathStr || this.pathFrom;
      if (this.isSubMch == 1 && this.goodsRoomId && this._socialType) {
        let goPath = this._playType == 2 ? 'liveVerticalRoom' : 'liveRoom';
        path = `/homePage/live/${goPath}?liveId=${this._liveId}&SocialRoomId=${this.goodsRoomId}`;
        //社群带货跳社群
        path = this._socialType == 1 ? `/homePage/socialGroup/chatRoom?SocialRoomId=${this.goodsRoomId}` : path;
      }
      return path;
    },
    isGoLiveRoom() {
      if (this.isSubMch == 1 && this.goodsRoomId && this._socialType) {
        return true;
      }
      return false;
    },
    paySuccessCallBack() {
      if (localStorage.getItem('promotedAccountId')) {
        sessionStorage.setItem('promotedAccountId', localStorage.getItem('promotedAccountId'))
        localStorage.removeItem('promotedAccountId');
      }
      //点金计划，直播带货支付成功之间跳直播间，不管其他
      if (this.isGoLiveRoom()) {
        let path = this.checkLiveGoods();
        this.$routerGo(this, "replace", { path: path })
        return;
      }
      if (this.isFrom == 4) {
        this.$routerGo(this, "replace", { path: '/member/myOrder/allOrderList', query: { orderType: -1 } });
        return;
      }
      let that = this;
      if (that.$route.query.isFrom == 3) { //升级服务商指定商品购买返回到升级服务商
        if (that.isSubMch == 1) {
          that.$routerGo(that, "replace", { path: that.pathFrom });
        } else {
          that.$router.go(-1);
        }
        return
      }
      if (!that.getRecommendGiftFlag && that.isActivity) {
        that.completetRecommendTask();
      } else if (that.$route.query.isFrom == 1) {
        that.hideQrcode();
      } else {
        if (!that.isActivity && (that.ptFrom == that.cfrom.vip || that.ptFrom == that.cfrom.svip || that.ptFrom == that.cfrom.flashSalesVip || that.ptFrom == that.cfrom.flashSalesSvip)) {
          if (that.good.gift && (that.good.gift.points || that.good.gift.familyCard || that.good.gift.coupon || that.good.isFreeGood == 1 || that.good.gift.vip || that.good.gift.svip)) { //如果是直接购买vip、svip或者限时购vip、svip，需要判断升级礼包是否为空
            that.showPresent = true;
          }
        }
      }
      this.getGuideData();
    },
    // paySuccessCallBack抽取代码
    paySuccessCallBackCon() {
      // 如果开启入群引导,入群引导支付成功页，否则按照正常
      if (this.companyAuth.version == 1) {
        this.isShowQr = true;
      } else if (this.isFrom != 1) {
        this.hideQrcode();
      }
    },
    //被推荐人完成推荐任务
    completetRecommendTask() {
      if (this.recType == 3 && this.recRelateId) {
        let data = { relateId: this.recRelateId, orderId: this.orderId };
        this.$nextTick(() => {
          this.$refs.recommendPresent.completetRecommendTask(data); // 调用子组件方法
        })
      }
    },
    //隐藏输入密码模块
    hidePwd() {
      this.showPassword = false;
    },
    confirmPwd(pwd) {
      this.password = pwd;
      this.showPassword = false;
      this.yuePay();
    },
    //切换付款模式
    changePayType(type) {
      if (this.isiOS) {
        this.payType = 2;
      } else if (type == 2 && !this.enablePayMember && Number(this.totalPrice) > 0) {
        this.payType = 1;
      } else if ((type == 1 || type == 3) && Number(this.totalPrice) == 0) {
        this.payType = 2;
      } else if (type == 2 && Number(this.totalPrice) > Number(this.balance) && Number(this.totalPrice) > 0) {
        this.payType = 1;
        this.$showCjToast({
          text: "余额不足",
          type: "warn",
        });
      } else {
        this.payType = type;
      }

      //    if (Number(this.balance) < Number(this.totalPrice)) {
      //      this.payType = this.payType;
      //      this.$showCjToast({
      //        text: "余额不足",
      //        type: "warn",
      //      });
      //    } else {
      //      this.payType = type;
      //    }
    },
    showSetPwdTip() {
      this.$cjConfirm({
        title: '提示',
        message: '您还未设置支付密码，去设置?',
        onConfirm:() => {
          this.onConfirm();
        }
      })
    },
    // 点击确定去设置密码
    onConfirm() {
      this.$routerGo(this, "push", { path: "/member/scholarship/updatePassword" });
    },
    // 隐藏关注公众号
    hideQrcode() {
      if (this.showPresent) { // 如果有赠送礼包弹窗，先不跳转页面
        return;
      }
      this.isShowQr = false;
      if (this.$route.query.fromCoursePay == 1) { //从课程支付页跳转到会员升级，会员升级完成后需要跳回课程详情
        localStorage.setItem("vipType" + localStorage.getItem("userId"), this.vipType);
        this.$router.go(-2);
      } else if (this.$route.query.type == this.cfrom.collageSvip || this.$route.query.type == this.cfrom.collageVip) {
        this.$routerGo(this, "replace", {
          path: "/homePage/collage/collageDetail",
          query: { 'groupId': this.$route.query.groupId, 'collageId': this.$route.query.collageId }
        });
      } else {
        localStorage.setItem("vipType" + localStorage.getItem("userId"), this.vipType);
        if (this.$route.query.type == this.cfrom.presentVip || this.$route.query.type == this.cfrom.presentSvip || this.$route.query.type == this.cfrom.flashSalesPresentVip || this.$route.query.type == this.cfrom.flashSalesPresentSvip || this.$route.query.isFrom == 1) {
          this.$routerGo(this, "replace", { path: '/homePage/course/presentCourse?orderId=' + this.orderId });
          sessionStorage.setItem(this.orderId + 'rewardPoints', this.rewardPoints);
        } else {
          this.$routerGo(this, "replace", { path: "/member/memberIndex" });
        }
      }
    },
    //使用优惠券
    clickCoupon(couponItem, couponIndex) {
      // 选取优惠券门槛金额大于标价时直接返回
      if (Number(couponItem.amount) > Number(this.getShowPrice())) {
        return;
      }

      if (this.choosedCouponIndex == couponIndex) {
        this.choosedCouponIndex = -1;
        this.choosedCouponId = -1;
        this.choosedCouponPrice = 0.00;
        this.choosedCouponDiscount = 1;
        this.amount = 0.00;
      } else {
        this.choosedCouponIndex = couponIndex;
        this.choosedCouponId = couponItem.rcdId;
        if (couponItem.type == 5) {
          this.choosedCouponDiscount = Number(couponItem.price) / 10;
          this.choosedCouponPrice = 0;
        } else {
          this.choosedCouponDiscount = 1;
          this.choosedCouponPrice = Number(couponItem.price);
        }
        this.amount = Number(couponItem.amount);
      }
      this.changeSwitch();
      this._calcCoin();
    },
    //关闭升级&推荐礼包
    closePresent() {
      this.showPresent = false;
      if (this.isActivity == 1) {
        this.paySuccessCallBack();
      }
    },
    //前往赠送记录
    goPresent() {
      isGoPresent = true;
    },
    //前往我的优惠券
    goMyValueVoucher() {
      isGoPresent = true;
    },
    //前往积分明细
    goMyPointDetail() {
      isGoPresent = true;
    },
    //前往会员中心
    goVipCentural() {
      this.$routerGo(this, "push", { path: "/member/vip/vipUp" });
    },
    showDiffUserTip() {
      this.$cjConfirm({
        title: '提示',
        message: '当前账户不是登录pc端账户，支付该套餐后只会在当前账户' + this.userName + '下有权限，是否继续支付?',
        onCancel:() => {
          this.goHome();
        }
      })

    },
    //前往首页
    goHome() {
      this.$routerGo(this, "replace", { path: '/' });
    },
    //分享
    wechatShare: function () {
      utilJs.wechatConfig("", "", "", "", function () { });
    },
    //手机端分享
    appShare: function () {
      utilJs.appShareTrue("", "", "", "");
    },
    resetCoupon(bfCoupPrice) {
      if (this.memberInfo.coupon != null) {
        let coupArr = this.memberInfo.coupon.enable;
        this.enableCoupon = coupArr.filter(item => Number(item.amount) <= Number(bfCoupPrice));
        this.unableCoupon = this.memberInfo.coupon.unable;
        if (this.enableCoupon.length > 0) {
          this.showCouponBtn = true;
        } else {
          this.showCouponBtn = false;
        }
      }
    },
    // 有关联表单，则跳到报名表单处
    goForm: function (ckFrom) { //vip relType14   svip relType15
      let pId = this.extraId ? this.extraId : -1;
      let relType = (ckFrom == this.cfrom.collageVip || ckFrom == this.cfrom.flashSalesVip || ckFrom == this.cfrom.vip || ckFrom == this.cfrom.flashSalesPresentVip) ? 14 : 15;
      let goFPath = this.$route.fullPath;
      let queryT = null;
      queryT = { cId: -1, extId: this.vId, ckFrom: ckFrom, isFromInvite: 0, isGoBack: 1, type: 1, relType: relType, pId: pId, goFPath: goFPath }
      if (this.$route.query.stepIndex) { //阶梯拼团
        queryT.stepIndex = this.$route.query.stepIndex;
      }
      this.$routerGo(this, "replace", { path: '/homePage/form', query: queryT });
    },
    getDefaultPayType() {
      let payType = -1;
      // 小程序不支持支付宝支付
      let enableAlipay = !!(localStorage.getItem("enableAlipay") == 1) && !this.$isWxApp();
      // （虚拟币 > 微信支付 > 支付宝支付 > 余额支付）除了价格为0的情况，余额支付优先，其他的情况都遵循这个优先级
      if (this.enableGiftCard) {
        payType = 2
      } else if (this.totalPrice == 0) {
        payType = 1
      } else if (this.payConf && this.payConf.enableWxpay == 1) {
        payType = 0
      } else if (enableAlipay) {
        payType = 3
      } else if (this.payConf.enablePayMember == 1 && Number(this.memberInfo.balance || 0) > 0 && Number(this.memberInfo.balance || 0) >= Number(this.totalPrice || 0)) {
        payType = 1
      }
      console.log(enableAlipay, payType, 'payType')
      this.payType = payType;
      this.$nextTick((res) => {
        if (!!this.$refs.payAndVip) {
          this.$refs.payAndVip.clickPayType(payType);
        }
      });
    },
    payShow: function (ckFrom, extraId) {
      let $this = this;
      let ckFromTmp = ckFrom == this.cfrom.collageVip ? this.cfrom.vip : ckFrom == this.cfrom.collageSvip ? this.cfrom.svip : (ckFrom == this.cfrom.flashSalesVip || ckFrom == this.cfrom.flashSalesPresentVip || ckFrom == this.cfrom.flashSalesPresentSvip) ? this.cfrom.vip : ckFrom;
      let payShowUrl = '';
      if (ckFrom == this.cfrom.flashSalesVip || ckFrom == this.cfrom.flashSalesPresentVip || ckFrom == this.cfrom.flashSalesPresentSvip) {
        payShowUrl = global.apiurl + "common/payShow?cId=0&extId=" + $this.vId + '&ckFrom=' + ckFromTmp + '&extraId=' + extraId + '&groupId=' + $this.groupId + '&orderId=' + this.orderId + '&mtkType=1';
      } else if (ckFrom == this.cfrom.collageVip || ckFrom == this.cfrom.collageSvip) {
        payShowUrl = global.apiurl + "common/payShow?cId=0&extId=" + $this.vId + '&ckFrom=' + ckFromTmp + '&extraId=' + extraId + '&groupId=' + $this.groupId + '&orderId=' + this.orderId + '&mtkType=2';
        if (this.$route.query.stepIndex) { //阶梯拼团
          payShowUrl = payShowUrl + "&stepIndex=" + this.$route.query.stepIndex;
        }
      } else if (this.attendId) {
        payShowUrl = global.apiurl + "common/payShow?cId=0&extId=" + $this.vId + '&ckFrom=' + ckFromTmp + '&extraId=' + extraId + '&groupId=' + $this.groupId + '&orderId=' + this.orderId + '&mtkType=12';
      } else if (this.recType == 3) {
        payShowUrl = global.apiurl + "common/payShow?cId=0&extId=" + $this.vId + '&ckFrom=' + ckFromTmp + '&extraId=' + extraId + '&groupId=' + $this.groupId + '&orderId=' + this.orderId + '&mtkType=19';
      } else {
        // 从好友赠送入口进入购买增加type区分是否是买赠
        let presentQuery = '';
        if (this.isFrom == 1 && (this.ptFrom == this.cfrom.presentVip || this.ptFrom == this.cfrom.presentSvip)) {
          presentQuery = `&presentType=${this.ptFrom}`
        }
        payShowUrl = global.apiurl + "common/payShow?cId=0&extId=" + $this.vId + '&ckFrom=' + ckFromTmp + '&extraId=' + extraId + '&groupId=' + $this.groupId + '&orderId=' + this.orderId + presentQuery;
      }
      utilJs.getMethod(payShowUrl, function (res) {
        // 有关联表单，则跳到报名表单处
        // 关联表单id是cId
        if ($this.isFrom == 0 && res.basic.isRelForm && res.basic.isRelForm == true && res.basic.hasFormLog == false && localStorage.getItem("showForm") == 1) {
          $this.goForm($this.ptFrom);
          return;
        }
        //基本数据
        $this._isCanUseGiftCard = res.basic.isCanUseGiftCard;
        $this.balance = res.basic.balance; //用户积分
        $this.memberInfo = res.basic; //用户基本信息
        $this.good = res.goods[0]; //商品信息
        $this._sellingPrice = res.goods[0].price;
        // 有新人价（产品说不算折扣价）优先按新人价计算，否则有续费价（产品说不算折扣价）按续费价算，否则再按原价，商品售价（虚拟币计算需要使用）
        if ($this.good.isNewUser && $this.good.newUserPrice) {
          $this._sellingPrice = Number($this.good.newUserPrice).toFixed(2);
        } else if ($this.good.isRenew && $this.good.isSetRenew == 1 && !!$this.good.renewRate && $this.ptFrom != $this.cfrom.presentVip && $this.ptFrom != $this.cfrom.presentSvip && $this.ptFrom != $this.cfrom.flashSalesPresentVip && $this.ptFrom != $this.cfrom.flashSalesPresentSvip) {
          $this._sellingPrice = Number($this.good.price * $this.good.renewRate / 100).toFixed(2);
        }
        $this.enablePayMember = res.payConf ? (res.payConf.enablePayMember == 0 ? false : true) : true;
        $this.payConf = res.payConf;
        $this.consigneeData = $this.good.unPayOrderExtra;
        $this.gzhQrCode = res.goods[0].companyQrcode.mpQrcode; //商品信息
        $this.isInvoice = res.basic.isInvoice;

        $this.getAddress();

        // 新人价 > 续费价，如果是新人价就不需要显示续费价
        $this.isShowReNew = !($this.good.isNewUser && $this.good.newUserPrice) && $this.good.isRenew &&
          $this.good.isSetRenew == 1 &&
          $this.good.renewRate !== null &&
          $this.recType != 3 &&
          $this.ptFrom != $this.cfrom.presentVip &&
          $this.ptFrom != $this.cfrom.presentSvip &&
          $this.ptFrom != $this.cfrom.flashSalesPresentVip &&
          $this.ptFrom != $this.cfrom.flashSalesSvip;

        if ($this.mtkType) {
          $this.chainInfo = '';
        } else {
          $this.chainInfo = res.chain;
        }
        $this.showPrice = $this.getShowPrice(); //标签价初始化
        $this.totalPrice = $this.getShowPrice(); //总价初始化
        $this.remainderPrice = $this.getShowPrice();
        if (!($this.isShowReNew && $this.good.duration > 0) && $this.chainInfo && $this.chainInfo.isChainProd && Number($this.chainInfo.chainDiscountPrice) > 0 && Number($this.chainInfo.chainDiscountPrice) < Number($this.showPrice)) {
          $this.totalPrice = Number($this.chainInfo.chainDiscountPrice);
          $this.remainderPrice = Number($this.chainInfo.chainDiscountPrice);
        }
        $this.getDeductible();
        // 根据当前价格获取可用的优惠券
        if ($this.isFrom != 4) {
          $this.resetCoupon($this.totalPrice);
        }
        // 用户有积分且商品开启积分抵扣时，积分抵扣可用
        if ($this.memberInfo.userPoints && $this.memberInfo.enablePoints && $this.good.deductiblePoints && Number($this.good.deductiblePoints) != 0) {
          $this.showDiscountPoints = true;
        }
        // 限时购、拼团、新人价、续费折扣不支持积分抵扣和使用优惠券
        if (
          ($this.good.isNewUser && $this.good.newUserPrice) ||
          ($this.good.renewRate && $this.good.isRenew && $this.good.isSetRenew == 1) || $this.attendId || $this.recRelateId) {
          $this.showCouponBtn = false;
          $this.showDiscountPoints = false;
        }
        if ($this.userId && $this.userId != res.basic.encodeUserId) {
          $this.showDiffUserTip();
        }
        $this.enableGiftCard = $this._getIsEnableGiftCard(res.goods[0]);
        $this.showPayAndVip = true;
        // 获取默认选中的paytype
        $this.getDefaultPayType();
        $this._calcCoin();
        if ($this.good && !$this.good.gift) {
          $this.good.gift = {}
        }
        // 将实物信息放入gift
        if ($this.good && $this.good.gift) {
          let cmpGift = {
            isFreeGood: $this.good.isFreeGood,
            freeGoodImg: $this.good.freeGoodImg,
            freeGoodName: $this.good.freeGoodName,
            freeGoodDesc: $this.good.freeGoodDesc,
            freeGoodArr: $this.good.giftRelates
          }
          $this.good.gift = { ...$this.good.gift, ...cmpGift }
        }
      });
    },
    //是否可以使用虚拟卡
    _getIsEnableGiftCard(goodsInfo = {}, giftCardInfo = this.giftCardInfo, isCanUseGiftCard = this._isCanUseGiftCard, mtkType = this.mtkType) {
      goodsInfo = goodsInfo || {};
      let flag = isCanUseGiftCard;
      if (utilJs.isAndroidApp() || utilJs.isIOSApp() || !Number(giftCardInfo.status) || (mtkType && ![1, 2].includes(mtkType * 1)) || this.ptFrom == this.cfrom.presentVip || this.ptFrom == this.cfrom.presentSvip || this.ptFrom == this.cfrom.flashSalesPresentVip || this.ptFrom == this.cfrom.flashSalesPresentSvip) {
        // 安卓ios端, 非限时购拼团的营销类型不能使用，买赠vip、svip也不允许使用虚拟币
        console.log("_getIsEnableGiftCard", false);
        return false;
      }
      console.log("_getIsEnableGiftCard", flag);
      return flag;
    },
    checkIsPresent() {
      let isPresent = this.ckFrom == this.cfrom.presentColumn || this.ckFrom == this.cfrom.presentCourse || this.ckFrom == this.cfrom.presentPackage || this.ckFrom == this.cfrom.presentEbooks || this.ckFrom == this.cfrom.presentCamp || false;
      return isPresent;
    },
  },
  async activated() {
    //为了ios app的审核
    this.isiOS = navigator.userAgent.indexOf('IOSLogin') > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1;
    this.payType = this.isiOS ? 1 : -1;
    await utilJs.getGiftCardInfo(1).then((res) => {
      this.giftCardName = res.name || "虚拟币";
      this.giftCardPic = res.coinImg || '';
      this.giftCardInfo = res;
    });
    if (this.isiOS) {
      //ios的游客身份
      this.$routerGo(this, "replace", { path: '/homePage/course/iosRecharge', query: { from: 1 } });
      return;
    }

    getBindPhoneSetting(global.ckFrom.vip).then(res => {
      this.bindPhoneSetting = res;
      if (this.bindPhoneSetting && this.bindPhoneSetting.buyBind) {
        let q = this.$route.query.noGoVipUp ? {} : { goVip: true };
        if (utilJs.goBindMobile(q)) return;
      }
      this.orderId = this.$route.query.orderId || ''; //订单id
      this.recType = this.$route.query.recType || '';
      this.recRelateId = this.$route.query.recRelateId || '';
      this.refereeId = this.$route.query.refereeId || '';
      this.ptFrom = this.$route.query.type;
      this.confirmShow = false;
      this.userName = localStorage.getItem("userName");
      this.goodsRoomId = this.$route.query.goodsRoomId || '';
      this.userId = this.$route.query.pcUserId || null; //要充值的用户ID
      this.groupId = this.$route.query.groupId || null; //拼团的groupId
      this.vId = this.$route.query.prodId; //选中的VIP种类ID
      this.pId = this.$route.query.pId || null; //限时购pId
      this.attendId = this.$route.query.attendId || ''; //砍价购id
      let extraId = this.$route.query.pId || this.$route.query.collageId || this.$route.query.attendId || this.recRelateId || null; //限时购extraId或拼团的collageId
      this.isActivity = (this.recType == 3 && this.recRelateId) ? 1 : 0;
      this.consigneeData = null;
      this.isShowAddressInfo = false;
      this.showAddress = false;
      this.name = '';
      this.mobile = '';
      this.addressSelected = [];
      this.consigneProvinceId = '';
      this.consigneeCityId = '';
      this.consigneeAreaId = '';
      this.address = '';
      this.addressDetail = '';
      this.addressDataList = [];
      this.isEmpty = false;
      this.isWechatPaying = false;
      this.isShowQr = false;
      this.protocolInfo = null;
      // if (localStorage.getItem("vipOrderInfo")) {
      //   this.isShowPolitely = true;
      //   this.orderInfo = JSON.parse(localStorage.getItem("vipOrderInfo"));
      // } else {
      //   this.isShowPolitely = false;
      // }
      this.showDiscountPoints = false;
      this.showCouponBtn = false;
      this.showCoup = false;
      this.enableCoupon = [];
      this.unableCoupon = [];
      this.choosedCouponPrice = 0.00;
      this.choosedCouponDiscount = 1;
      this.choosedCouponIndex = -1;
      this.choosedCouponId = -1;
      this.showPresent = false;
      this.getRecommendGiftFlag = false;
      this.presentList = '';
      this.rewardPoints = 0;
      this.showPoints = false;
      this.showPrice = 0;
      this.totalPrice = 0;
      this.good = { cover: { coverUrl: '' }, gift: {} };
      this.isShowAddressInfo = false;
      this.showPassword = false;
      isGoPresent = false;
      this.isSubMch = 0;
      this.remainderPrice = 0;
      this.showPayAndVip = false;
      this.hasGoodsGiftNew = false;
      this.hasGoodsGiftOld = false;
      this.showAddressModal = false;
      this.invoiceInfo = null;
      this.showInvoice = false;
      if (this.ptFrom == this.cfrom.presentVip || this.ptFrom == this.cfrom.presentSvip || this.ptFrom == this.cfrom.flashSalesPresentVip || this.ptFrom == this.cfrom.flashSalesPresentSvip) {
        setDocumentTitle("会员买赠");// eslint-disable-line
      } else if (Number(this.$route.query.isFrom) == 4) {
        setDocumentTitle("团购");// eslint-disable-line
      } else {
        setDocumentTitle("升级会员");// eslint-disable-line
      }
      // common/payShow接口对vip和svip进行了合并，不区分
      let ckFrom = null;
      if (this.ptFrom == this.cfrom.vip || this.ptFrom == this.cfrom.svip) {
        ckFrom = this.cfrom.vip;
      } else if (this.ptFrom == this.cfrom.presentVip || this.ptFrom == this.cfrom.presentSvip) {
        ckFrom = this.cfrom.vip; //赠送会员在提交订单时区分
      } else if (this.ptFrom == this.cfrom.collageVip || this.ptFrom == this.cfrom.collageSvip) {
        ckFrom = this.cfrom.collageVip;
      } else if (this.ptFrom == this.cfrom.flashSalesVip || this.ptFrom == this.cfrom.flashSalesSvip) {
        ckFrom = this.cfrom.flashSalesVip;
      } else if (this.ptFrom == this.cfrom.flashSalesPresentVip || this.ptFrom == this.cfrom.flashSalesPresentSvip) {
        ckFrom = this.cfrom.flashSalesVip;
      }
      if (!checkEnableModule(ckFrom, this)) {
        return;
      }
      if (this.ptFrom == this.cfrom.vip ||
        this.ptFrom == this.cfrom.presentVip ||
        this.ptFrom == this.cfrom.collageVip ||
        this.ptFrom == this.cfrom.flashSalesVip ||
        this.ptFrom == this.cfrom.flashSalesPresentVip) {
        this.vipType = 2;
      } else { this.vipType = 4; }
      this.isFrom = this.$route.query.isFrom || 0;
      if (this.$route.query.isWechatH5Pay == 1 && localStorage.getItem("payFromPath")) {
        let payFromPath = localStorage.getItem("payFromPath");
        localStorage.removeItem("payFromPath")
        window.location.replace(payFromPath);
        return;
      } else if (this.$route.query.isGoldPlan == 1 && localStorage.getItem("shopPayBack")) { //微信支付后点击回到这个页面
        let ls = JSON.parse(localStorage.getItem("shopPayBack"));
        this.orderId = ls.orderId;
        this.isSubMch = ls.isSubMch;
        this._liveId = ls.liveId || '';
        this.goodsRoomId = ls.goodsRoomId || '';
        this._socialType = ls.socialType || '';
        this._playType = ls.playType || '';
        this.pathFrom = ls.pathFrom;
        this.gzhQrCode = ls.gzhQrCode;
        this.good = ls.good;
        localStorage.removeItem("shopPayBack")
        this.paySuccessCallBack();
        return;
      } else if (localStorage.getItem("shopPayBack") || localStorage.getItem("payFromPath")) {
        localStorage.removeItem("shopPayBack")
        localStorage.removeItem("payFromPath")
      }
      if (localStorage.getItem('promotedAccountId')) {
        localStorage.removeItem('promotedAccountId');
      }
      this.mtkType = this.isFrom == 4 ? 22 : this.recRelateId && !this.checkIsPresent() ? 19 : this.attendId ? 12 : (flashCkFromOld[this.ckFrom] && flashCkFromOld[this.ckFrom] != undefined) || (this.pId && this.pId != -1) ? "1" : collageCkFromOld[this.ckFrom] ? "2" : "";
      if (this.isFrom == 0 || this.isFrom == 3) {
        this.payShow(ckFrom, extraId);
      }
      this.wechatShare();
      this.getProdProtocol();
    });
  },
  beforeRouteLeave(to, from, next) {
    if ((to.path == '/member/presentCourse/presentCourseList' || to.path == '/member/myValueVoucher/myValueVoucher' || to.path == '/member/myIntegral/integralDetail') && this.orderInfo && this.isShowPolitely && isGoPresent && this.showPresent) {
      localStorage.setItem("vipOrderInfo", JSON.stringify(this.orderInfo));
    } else {
      if (localStorage.getItem("vipOrderInfo")) {
        localStorage.removeItem("vipOrderInfo")
      }
    }
    next();
  },
  deactivated() {
    this.payType = -1;
    this.isUserPoints = 0;
    this.rewardPoints = 0;
    this.showCouponBtn = false;
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.buy-btn {
  color: #eadbac;
  background: linear-gradient(#252531 0%, #4e4e5c 0%, #23232f 100%);
}
.coupon-mb2 {
  background: url("../../../../public/i/wap/vip/coupon-mb2.png");
  background-size: cover;
}
.c-ww124 {
  width: 3.1rem;
}
.masker {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1002;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}
.content {
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1003;
  margin: 0 auto;
  background-color: #fff;
}
.c-bg-coupon {
  background-color: #f4f7f9;
}
.close {
  position: absolute;
  right: 0.6rem;
  top: 0.4rem;
}
.c-maxh400 {
  max-height: 10rem;
}
.c-br18 {
  border-radius: 0.45rem;
}
/* 关注二维码样式 */
.maskerContent {
  width: 90%;
  position: fixed;
  top: 1rem;
  left: 5%;
  z-index: 1005;
}
.payMasker {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1004;
  width: 100%;
  height: 100%;
  background-color: #f0f1f5;
}
.payPolitelyMasker {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1004;
  width: 100%;
  height: 100%;
  background-color: #fff;
}
.view-btn {
  border: 1px solid #23db85;
}
.c-mb60 {
  margin-bottom: 1.5rem;
}
.dialog-mid {
  background: url("../../../assets/i/wap/vip/gift-package-mid.png") no-repeat;
  background-size: 100% 100%;
  padding-right: 0.4rem;
}
.exchange-left {
  background: url("../../../../public/i/wap/coupon/coupon_left.png") no-repeat
    100%;
  background-size: 100% 100%;
}
.all-coupon-bg {
  background-color: #f4f7f9;
}

.family-card-bg {
  background: url("../../../assets/i/wap/vip/familyCard.png");
  background-size: cover;
  padding-left: 3.45rem;
  padding-right: 0.35rem;
}
.equity-vip-bg {
  background: url("../../../assets/i/wap/recommend/VIP.png");
  background-size: cover;
  padding-left: 3.45rem;
  padding-right: 0.35rem;
}
.equity-svip-bg {
  background: url("../../../assets/i/wap/recommend/SVIP.png");
  background-size: cover;
  padding-left: 3.45rem;
  padding-right: 0.35rem;
}
.dia-head-bg {
  padding-top: 5rem;
}
.coupon-mb1 {
  background: url("../../../../public/i/wap/vip/coupon-mb1.png");
  background-size: cover;
}
.exchange-left1 {
  background: url("../../../../public/i/wap/coupon/exchange.png") no-repeat 100%;
  background-size: 100% 100%;
}
.knowBtn {
  background: linear-gradient(
    -90deg,
    rgba(72, 147, 248, 1),
    rgba(72, 147, 248, 0.7)
  );
}
.goodsDetail >>> img {
  width: 100%;
}
.goodsDetail >>> p {
  width: 100%;
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
  word-wrap: break-word;
  color: #666666;
  font-size: 0.6rem;
  line-height: 1.2rem;
  text-align: left;
}
.goodsDetail >>> span {
  width: 100%;
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
  word-wrap: break-word;
  color: #666666;
  font-size: 0.6rem;
  line-height: 1.2rem;
  text-align: left;
}
.addressSelected >>> .vux-popup-picker-placeholder {
  color: #cccccc;
}
.invalid >>> .vux-popup-picker-placeholder {
  color: #fc583d !important;
}
.invalid::-webkit-input-placeholder {
  color: #fc583d;
}
.invalid::-moz-input-placeholder {
  color: #fc583d;
}
.invalid::-ms-input-placeholder {
  color: #fc583d;
}
input.invalid::-webkit-input-placeholder {
  color: #fc583d;
}
input.invalid::-moz-input-placeholder {
  color: #fc583d;
}
input.invalid::-ms-input-placeholder {
  color: #fc583d;
}
</style>
